package com.learning.spring.ioc.type.conversion.formatter;

import org.springframework.format.Formatter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * ClassName: CusDateFormatter
 * Description: 自定义的 Formatter
 * Date: 2020/7/22 9:52 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class CusDateFormatter implements Formatter<Date> {

    @Override
    public Date parse(String text, Locale locale) throws ParseException {
        return getSimpleDateFormat().parse(text);
    }

    @Override
    public String print(Date date, Locale locale) {
        return getSimpleDateFormat().format(date);
    }


    private SimpleDateFormat getSimpleDateFormat() {
        return new SimpleDateFormat("yyyy-MM-dd");
    }
}